#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@File ：UserRoleModel.py
@Author ：zqy
@Email : zqingy@work@163.com
@note:
"""
from sqlalchemy import Integer, Column, ForeignKey
from sqlalchemy.orm import relationship

from application.util.MysqlUtil import mysql_db


class UserRoleModel(mysql_db.Model):
    """
    用户-角色关联表
    """
    __tablename__: str = "user_role"
    # 主键
    id = Column(Integer, primary_key=True, unique=True, autoincrement=True, comment="主键，自增")
    # 用户ID
    user_id = Column(Integer, ForeignKey('user.id'), comment="用户ID")
    # 角色ID
    role_id = Column(Integer, ForeignKey('role.id'), comment="用户ID")

    user = relationship("User", back_populates="roles")
    role = relationship("RoleModel", back_populates="users")
